<template>
  <div class="comment">
    <!-- 姓名 点赞区域 -->
    <div class="info-box">
      <img
      @click="clickAvatar"
       :src="itemData.author.avatar | addBaseUrl" alt="" />
      <div class="name-box">
        <span class="name">{{ itemData.author.nickname }}</span>
        <span class="time">{{ itemData.created_at | formatTime }}</span>
      </div>
      <div class="zan-box actived">
        <span>{{ itemData.star }}</span>
        <i class="iconfont iconbtn_dianzan_small_nor "></i>
      </div>
    </div>
    <!-- 评论内容 -->
    <div class="content-box">
      <div class="content">{{ itemData.content }}</div>
      <div class="reply-box" v-if="itemData.children_comments.length">
        <div class="reply"
          v-for="item in itemData.children_comments"
          :key="item.id"
        >
          <span class="name">{{ item.author }}:</span>
          <span class="content">{{ item.content }}</span>
        </div>
      </div>
    </div>
    <!-- 回复评论 -->
  </div>
</template>

<script>
export default {
  name: 'comment-item',
  props: ['itemData'],
  methods: {
    // 这个事件被抛出去之后,需要父组件接一下
    clickAvatar () {
      this.$emit('clickAvatar', this.itemData)
    }
  }
}
</script>

<style lang="less">
.comment {
  .info-box {
    margin-top: 15px;
    display: flex;
    align-items: center;
    img {
      width: 35px;
      height: 35px;
      border-radius: 50%;
      margin-right: 9px;
    }
    .name-box {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      .name {
        font-size: 12px;
        font-weight: 600;
        color: @subdominant-font-color;
      }
      .time {
        font-size: 12px;
        color: @minor-font-color;
      }
    }
    .zan-box {
      span {
        color: @minor-font-color;
        font-size: 12px;
      }
      .iconfont {
        color: @minor-font-color;
        font-size: 24px;
      }
      &.actived {
        span {
          color: @main-color;
        }
        .iconfont {
          color: @main-color;
        }
      }
    }
  }
  .content-box {
    padding-left: 44px;
    .content {
      margin-top: 11px;
      font-size: 16px;
      color: @main-font-color;
      line-height: 27px;
    }
    .reply-box {
      margin-top: 5px;
      padding-left: 15px;
      padding-bottom: 12px;
      background: @border-color;
      .reply {
        font-size: 14px;
        color: @subdominant-font-color;
        padding-top: 15px;
        .name {
          font-weight: 500;
          margin-right: 5px;
        }
        .content {
          word-break: break-all;
          word-wrap: break-word;
        }
      }
    }
  }
}
</style>
